package com.libgdxbar.pvzlikegame.entities;

import com.badlogic.gdx.math.Vector2;

// 可移动的实体
public class MoveEntity extends LocationEntity {
    final Vector2 velocity;

    public MoveEntity() {
        this(0, 0);
    }

    public MoveEntity(Vector2 position) {
        this(position.x, position.y);
    }

    public MoveEntity(float x, float y) {
        this(x, y, 0, 0);
    }

    public MoveEntity(Vector2 position, Vector2 velocity) {
        this(position.x, position.y, velocity);
    }

    public MoveEntity(float x, float y, Vector2 velocity) {
        this(x, y, velocity.x, velocity.y);
    }

    public MoveEntity(float x, float y, float velocityX, float velocityY) {
        super(x, y);
        velocity = new Vector2(velocityX, velocityY);
    }

    @Override
    public void run(float delta) {
        position.x += getVelocityX() * delta;
        position.y += getVelocityY() * delta;
    }

    public Vector2 getVelocity() {
        return velocity;
    }

    public void setVelocity(Vector2 velocity) {
        velocity.set(velocity);
    }

    public void setVelocity(float x, float y) {
        velocity.set(x, y);
    }

    public void setVelocityX(float velocityX) {
        velocity.x = velocityX;
    }

    public void setVelocityY(float velocityY) {
        velocity.y = velocityY;
    }

    public float getVelocityX() {
        return velocity.x;
    }

    public float getVelocityY() {
        return velocity.y;
    }
}
